package com.yymmarket.util;

import java.util.HashSet;
import java.util.List;
import java.util.regex.Pattern;

import com.yymmarket.util.db.DbOperation;
/**
 * 
 *  @author LeiHongyun  2010-10-27 09:49:54
 *
 */
public class ForbidUtil {

	public static Pattern banWord = Pattern.compile("");

	public static String replaceTo = "";
	
	public static HashSet<String> forbidSet = null;
	
	public static HashSet<String> getForbidSet(){
		if(forbidSet == null) {
			synchronized(ForbidUtil.class) {
				if(forbidSet == null) {
					forbidSet = new HashSet<String>();
					List list = SqlUtil.getObjectList("select forbid_str from main_forbid",DbOperation.YYMMarket);
					for (Object object : list) {
						String str = (String)object;
						forbidSet.add(str);
					}
				}
			}
		}
		return forbidSet;
	}
	
	public static boolean isBanWord(String word) {
		return banWord.matcher(word).lookingAt();
	}

	public static String replaceBanWord(String word) {
		return banWord.matcher(word).replaceAll(replaceTo);
	}

}
